from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select


class FinancePage(BasePage):
    #当前url
    url = "/crm/index.php?m=finance"
    #定位器
    #回收站跳转定位器
    finance_delete_station_locator = (By.CSS_SELECTOR, "body > div.container > p > a:nth-child(18)")
    #添加应收款按钮定位器
    finance_add_gathering_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div.pull-right > a:nth-child(1)")
    #添加付款单按钮定位器
    finance_add_payment_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div.pull-right > a:nth-child(2)")
    #查看应收款合同定位器
    finance_see_locator = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(4) > td:nth-child(11) > a:nth-child(1)")
    #勾选应收款合同确认定位器
    choice_locator = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input")
    #删除按钮定位器
    delete_locator = (By.ID, "delete")
    #选择搜索字段选择框定位器
    order_search_select_locator = (By.ID, "field")
    #搜索输入框定位器
    order_search_input_locator = (By.ID, "search")
    #搜索按钮定位器
    order_search_btn_locator = (By.CSS_SELECTOR, "#searchForm > ul > li:nth-child(4) > button")
    #左上角财务定位器
    left_finance_text_locator = (By.CSS_SELECTOR,"body > div.container > div.page-header")
    #删除成功定位器
    delete_message_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")


    #执行的页面操作
    #点击回收站跳转按钮
    def finance_page_delete_station_jump_click(self):
        self.find_element(self.finance_delete_station_locator).click()
    #点击添加应收款按钮
    def finance_page_add_gathering_order(self):
        self.find_element(self.finance_add_gathering_locator).click()
    #点击添加收款单按钮
    def finance_page_add_payment_order(self):
        self.find_element(self.finance_add_payment_locator).click()
    #点击查看应收款信息
    def finance_page_see_click(self):
        self.find_element(self.finance_see_locator).click()
    #点击勾选应收款的第一项
    def finance_page_delete_table_choice(self):
        self.find_element(self.choice_locator).click()
    #点击删除
    def finance_page_delete_click(self):
        self.find_element(self.delete_locator).click()
    def alert_make_sure(self):
        self.driver.switch_to.alert.accept()
    #选择搜索字段
    def finance_page_search_select_choice(self,text4):
        order_search_select_element = self.find_element(self.order_search_select_locator)
        order_search_select_select = Select(order_search_select_element)
        order_search_select_select.select_by_visible_text(text4)
    #输入搜索信息
    def finance_page_search_input(self,order_search_input):
        self.find_element(self.order_search_input_locator).send_keys(order_search_input)
    #点击搜索按钮
    def finance_page_search_btn_click(self):
        self.find_element(self.order_search_btn_locator).click()
    #获取左上角财务标题的文本信息
    def left_finance_text(self):
        return self.find_element(self.left_finance_text_locator).text
    #获取删除成功文本信息
    def delete_massage(self):
        return self.find_element(self.delete_message_locator).text
    #获取回收站跳转URL
    def delete_station_jump(self):
        return self.driver.current_url
    #获取搜索跳转url
    def search_jump(self):
        return self.driver.current_url


